package cn.kxlove.zhbj;

import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.Window;

import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu;
import com.jeremyfeinstein.slidingmenu.lib.app.SlidingFragmentActivity;

import cn.kxlove.zhbj.fragment.ContentFragment;
import cn.kxlove.zhbj.fragment.LeftMenuFragment;

public class MainActivity extends SlidingFragmentActivity {

    private static final String TAG_LEFT_MENU = "TAG_LEFT_MENU";
    private static final String TAG_CONENT = "TAG_CONTENT";
    private SlidingMenu slidingMenu;


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_main);

        setBehindContentView(R.layout.left_menu);

        slidingMenu = getSlidingMenu();
        slidingMenu.setBehindOffset(200);
        slidingMenu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
        initFragment();
    }

    /**
     * 初始化Fragment
     */
    private void initFragment() {
        FragmentManager fm = getSupportFragmentManager();// Fragment管理器
        FragmentTransaction transaction = fm.beginTransaction();// 开始事务
        transaction.replace(R.id.fl_left_menu, new LeftMenuFragment(),
                TAG_LEFT_MENU);// 用fragment替换帧布局,参1:帧布局的id;参2:要替换的Fragment
        transaction.replace(R.id.fl_main, new ContentFragment(), TAG_CONENT);
        transaction.commit();
    }

    /*
	 * 获取侧边栏Fragment对象
	 */
    public LeftMenuFragment getLeftMenuFragment() {
        FragmentManager fm = getSupportFragmentManager();// Fragment管理器
        return (LeftMenuFragment) fm.findFragmentByTag(TAG_LEFT_MENU);
    }

    /*
     * 获取主页Fragment对象
     */
    public ContentFragment getContentFragment() {
        FragmentManager fm = getSupportFragmentManager();// Fragment管理器
        return (ContentFragment) fm.findFragmentByTag(TAG_CONENT);
    }

}
